package com.atguigu.service.impl;

import com.atguigu.dao.TomcatAndHeartbeatServiceConfigDao;
import com.atguigu.dao.impl.TomcatAndHeartbeatServiceConfigDaoImpl;
import com.atguigu.pojo.Page;
import com.atguigu.pojo.TomcatAndHeartbeatServiceConfig;
import com.atguigu.service.TomcatAndHeartbeatServiceConfigService;

import java.util.List;

public class TomcatAndHeartbeatServiceConfigServiceImpl implements TomcatAndHeartbeatServiceConfigService {
    TomcatAndHeartbeatServiceConfigDao tomcatAndHeartbeatServiceConfigDao=new TomcatAndHeartbeatServiceConfigDaoImpl();
    @Override
    public void addTomcatAndHeartbeatServiceConfig(TomcatAndHeartbeatServiceConfig tomcatAndHeartbeatServiceConfig) {
        tomcatAndHeartbeatServiceConfigDao.addTomcatAndHeartbeatServiceConfig(tomcatAndHeartbeatServiceConfig);
    }

    @Override
    public void updateTomcatAndHeartbeatServiceConfig(TomcatAndHeartbeatServiceConfig tomcatAndHeartbeatServiceConfig) {
        tomcatAndHeartbeatServiceConfigDao.updateTomcatAndHeartbeatServiceConfig(tomcatAndHeartbeatServiceConfig);
    }

    @Override
    public void deleteTomcatAndHeartbeatServiceConfigById(String id) {
        tomcatAndHeartbeatServiceConfigDao.deleteTomcatAndHeartbeatServiceConfigById(id);
    }

    @Override
    public TomcatAndHeartbeatServiceConfig queryTomcatAndHeartbeatServiceConfigById(String id) {
        return tomcatAndHeartbeatServiceConfigDao.queryTomcatAndHeartbeatServiceConfigById(id);
    }

    @Override
    public List<TomcatAndHeartbeatServiceConfig> queryTomcatAndHeartbeatServiceConfigs() {
        return tomcatAndHeartbeatServiceConfigDao.queryTomcatAndHeartbeatServiceConfigs();
    }
    @Override
    public TomcatAndHeartbeatServiceConfig queryTomcatAndHeartbeatServiceConfigByServiceId(String serviceId){
        return tomcatAndHeartbeatServiceConfigDao.queryTomcatAndHeartbeatServiceConfigByServiceId(serviceId);
    }
    @Override
    public List<TomcatAndHeartbeatServiceConfig> queryTomcatAndHeartbeatServiceConfigsByProjectModuleId(String projectModuleId){
        return tomcatAndHeartbeatServiceConfigDao.queryTomcatAndHeartbeatServiceConfigsByProjectModuleId(projectModuleId);
    }

    @Override
    public Page page(Integer pageNo, Integer pageSize) {
        Page<TomcatAndHeartbeatServiceConfig> page=new Page<>();
        page.setPagesize(pageSize);
        Integer pageTotalCount=tomcatAndHeartbeatServiceConfigDao.queryForPageTotalCount();
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal=pageTotalCount/pageSize;
        if(pageTotalCount % pageSize >0){
            pageTotal++;//总条数,除以一页条数,大于0,页码数+1
        }
        page.setPageTotal(pageTotal);
        System.out.println("pageNo 原来是 is:"+pageNo);
        if(pageNo<1){//防止用户输入量太大
            pageNo=1;
        }else if(pageNo>pageTotal){
            pageNo=pageTotal;
        }
        page.setPageNo(pageNo);//当前页码
        System.out.println("pageNo 现在是 is:"+pageNo);
        System.out.println("pageTotal is:"+pageTotal);
        //要得到的是page的items
        Integer begin=(page.getPageNo()-1)*pageSize;
        List<TomcatAndHeartbeatServiceConfig> items=tomcatAndHeartbeatServiceConfigDao.queryForPageItems(begin,pageSize);
        page.setItems(items);
        return page;
    }
}
